<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title><?php print $name; ?>列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1">
    <link rel="stylesheet" href="/theme/admin/assets/css/index.css">
    <link rel="stylesheet" href="/theme/admin/assets/css/font_style.css">
    <link rel="stylesheet" href="/theme/admin/assets/layui/css/layui.css">
</head>

<body>
    <div class="tab-body">
        <div class="handle-box">
            <ul>
                <li class="handle-item"><a href="javascript:;" onclick="<?php print $type; ?>Add();" class="layui-btn btn-add btn-default" id="btn-add<?php print $type; ?>"><i class="linyer icon-add"></i> 添加<?php print $name; ?></a></li>
            </ul>
        </div>
        <table class="table-box table-sort" id="userTable">
            <thead>
                <tr>
                  <th>ID</th>
                  <th>Title</th>
                  <th>Created</th>
                  <th>Operations</th>
                </tr>
            </thead>
            <tbody>
              <?php print '<?php foreach ($'.$type.'s as $r): ?>'; ?>

                  <tr role="row" class="even">
                    <td>
                        <?php print '<?php echo $r->'.substr($type, 0, 1 ); ?>id; ?>
                    </td>
                    <td>
                        <?php print '<?php echo $r->title; ?>'; ?>

                    </td>
                    <td>
                        <?php print '<?php echo date("Y-m-d H:i:s", $r->created); ?>'; ?>

                    </td>
                    <td class=" td-handle">
                        <a href="javascript:;" onclick="<?php print $type; ?>Edit('<?php print '<?php echo $r->'.substr($type, 0, 1 ); ?>id; ?>');" class="layui-btn layui-btn-normal layui-btn-mini">编辑</a>
                        <a href="javascript:;" onclick="<?php print $type; ?>Del('<?php print '<?php echo $r->'.substr($type, 0, 1 ); ?>id; ?>');" class="layui-btn layui-btn-danger layui-btn-mini ajax-delete">删除</a>
                    </td>
                </tr>
              <?php print '<?php endforeach;?>';?>

            </tbody>
        </table>
        <input id="iframe_status" value="" hidden="hidden">
    </div>
    <script src="/theme/admin/assets/layui/layui.js"></script>
    <script src="/theme/admin/assets/js/define/common.js"></script>
    <script>
        function <?php print $type; ?>Add() {
            layui.use(['layer'], function() {
                var $ = layui.jquery;
                var layer = layui.layer;

                var index = layer.open({
                    title: '添加<?php print $name; ?>',
                    type: 2,
                    area: ['800px', '590px'],
                    fix: false, //不固定
                    maxmin: true,
                    content: ['/admin/<?php print $type; ?>/add', 'yes'],
                    success: function(layero, index) {},
                    end: function() {
                        var iframe_status = $("#iframe_status").val();
                        if (iframe_status == '1') {
                            layer.msg('Create success!', {
                                icon: 1,
                                time: 1000,
                                shade: 0.1
                            }, function() {
                                location.reload();
                            });
                        } else if (iframe_status == '0') {
                            layer.msg('Create failed!', {
                                icon: 5
                            });
                        }
                    }
                });
                layer.full(index);
            });
        }

        function <?php print $type; ?>Edit(<?php print substr($type, 0, 1 ); ?>id) {
            layui.use(['layer'], function() {
                var $ = layui.jquery;
                var layer = layui.layer;

                var index = layer.open({
                    title: '编辑<?php print $name; ?>',
                    type: 2,
                    area: ['800px', '590px'],
                    fix: false, //不固定
                    maxmin: true,
                    content: ['/admin/<?php print $type; ?>/edit/' + <?php print substr($type, 0, 1 ); ?>id, 'yes'],
                    success: function(layero, index) {},
                    end: function() {
                        var iframe_status = $("#iframe_status").val();
                        if (iframe_status == '1') {
                            layer.msg('Edit success！', {
                                icon: 1,
                                time: 1000,
                                shade: 0.1
                            }, function() {
                                location.reload();
                            });
                        } else if (iframe_status == '0') {
                            layer.msg('No edit content!', {
                                icon: 5
                            });
                        } else if (iframe_status == '') {}
                    }
                });
                layer.full(index);
            });
        }

        function <?php print $type; ?>Del(<?php print substr($type, 0, 1 ); ?>id) {
            layui.use(['layer'], function() {
                var $ = layui.jquery;
                var layer = layui.layer;

                layer.confirm('你确定要删除此项吗?', {
                    icon: 3,
                    title: '删除<?php print $name; ?>'
                }, function(index) {
                    $.ajax({
                        type: "GET",
                        url: '/admin/<?php print $type; ?>/del/' + <?php print substr($type, 0, 1 ); ?>id,
                        success: function(msg) {
                            if (msg) { //如果成功了
                                layer.msg('删除成功!', {
                                    icon: 1,
                                    time: 1000,
                                    shade: 0.1
                                }, function() {
                                    location.reload();
                                });
                            } else {
                                layer.msg('删除失败!', {
                                    icon: 5
                                });
                            }
                        }
                    });
                });
            });
        }
    </script>
</body>

</html>
